"use strict";(globalThis.webpackChunk_github_ui_github_ui=globalThis.webpackChunk_github_ui_github_ui||[]).push([["packages_relay-environment_relay-environment_ts"],{11418:(e,t,r)=>{let s;r.d(t,{H:()=>$});var n=r(35750),i=r(18150),a=r(85242),o=r(88243),l=r(16213),u=r(10204),c=new WeakMap,h=new WeakSet;let AliveSession=class AliveSession extends u.ib{constructor(e,t,r,s,n){super(e,()=>(0,o._)(this,h,d).call(this),r,s,void 0,n),(0,l._)(this,h),(0,i._)(this,c,{writable:!0,value:void 0}),(0,a._)(this,c,t)}};function d(){return p((0,n._)(this,c))}async function p(e){let t=await f(e);return t&&t.url&&t.token?g(t.url,t.token):null}async function f(e){let t=await fetch(e,{headers:{Accept:"application/json"}});if(t.ok)return t.json();if(404===t.status)return null;throw Error("fetch error")}async function g(e,t){let r=await fetch(e,{method:"POST",mode:"same-origin",headers:{"Scoped-CSRF-Token":t}});if(r.ok)return r.text();throw Error("fetch error")}var b=r(70170),w=r(34095),m=r(82075),_=r(23683),S=r(69599);function y(e,{channel:t,type:r,data:s}){for(let n of e)n.dispatchEvent(new CustomEvent(`socket:${r}`,{bubbles:!1,cancelable:!1,detail:{name:t,data:s}}))}var v=new WeakMap,k=new WeakMap,E=new WeakMap,T=new WeakMap,M=new WeakMap,P=new WeakSet;let A=class AliveSessionProxy{subscribe(e){let t=(0,n._)(this,k).add(...e);t.length&&(0,n._)(this,v).port.postMessage({subscribe:t});let r=new Set(t.map(e=>e.name)),s=e.reduce((e,t)=>{let s=t.topic.name;return(0,u.JR)(s)&&!r.has(s)&&e.add(s),e},new Set);s.size&&(0,n._)(this,v).port.postMessage({requestPresence:Array.from(s)})}unsubscribeAll(...e){let t=(0,n._)(this,k).drain(...e);t.length&&(0,n._)(this,v).port.postMessage({unsubscribe:t});let r=(0,n._)(this,E).removeSubscribers(e);this.sendPresenceMetadataUpdate(r)}updatePresenceMetadata(e){let t=new Set;for(let r of e)(0,n._)(this,E).setMetadata(r),t.add(r.channelName);this.sendPresenceMetadataUpdate(t)}sendPresenceMetadataUpdate(e){if(!e.size)return;let t=[];for(let r of e)t.push({channelName:r,metadata:(0,n._)(this,E).getChannelMetadata(r)});(0,n._)(this,v).port.postMessage({updatePresenceMetadata:t})}online(){(0,n._)(this,v).port.postMessage({online:!0})}offline(){(0,n._)(this,v).port.postMessage({online:!1})}hangup(){(0,n._)(this,v).port.postMessage({hangup:!0})}constructor(e,t,r,s,c,h){(0,l._)(this,P),(0,i._)(this,v,{writable:!0,value:void 0}),(0,i._)(this,k,{writable:!0,value:new u.m0}),(0,i._)(this,E,{writable:!0,value:new u.VH}),(0,i._)(this,T,{writable:!0,value:void 0}),(0,i._)(this,M,{writable:!0,value:new Map}),(0,a._)(this,T,c),(0,a._)(this,v,new SharedWorker(`${e}?module=true`,{name:`github-socket-worker-v3-${s}`,type:"module"})),(0,n._)(this,v).port.onmessage=({data:e})=>(0,o._)(this,P,N).call(this,e),(0,n._)(this,v).port.postMessage({connect:{url:t,refreshUrl:r,options:h}})}};function N(e){let{channel:t}=e;if("presence"===e.type){let r=(0,n._)(this,M).get(t);r||(r=(0,b.s)((e,r)=>{(0,n._)(this,T).call(this,e,r),(0,n._)(this,M).delete(t)},100),(0,n._)(this,M).set(t,r)),r((0,n._)(this,k).subscribers(t),e);return}(0,n._)(this,T).call(this,(0,n._)(this,k).subscribers(t),e)}async function O(){let e=function(){let e=document.head.querySelector("link[rel=shared-web-socket-src]")?.getAttribute("href");return e&&e.startsWith("/")?e:null}();if(!e)return;let t=document.head.querySelector("link[rel=shared-web-socket]")?.href??null;if(!t)return;let r=document.head.querySelector("link[rel=shared-web-socket]")?.getAttribute("data-refresh-url")??null;if(!r)return;let s=document.head.querySelector("link[rel=shared-web-socket]")?.getAttribute("data-session-id")??null;if(!s)return;let n=(()=>{let n=(0,S.G7)("alive_legacy_retries")?{socketPolicy:{timeout:4e3,attempts:7}}:{};if(!(0,_.nr)()&&"SharedWorker"in window&&"true"!==(0,m.A)("localStorage").getItem("bypassSharedWorker"))try{return new A(e,t,r,s,y,n)}catch{}return new AliveSession(t,r,!1,y,n)})();return window.addEventListener("online",()=>n.online()),window.addEventListener("offline",()=>n.offline()),window.addEventListener("pagehide",()=>{"hangup"in n&&n.hangup()}),n}async function I(){return await w.G,O()}function $(){return s||(s=I())}},30721:(e,t,r)=>{r.d(t,{VB:()=>SSRNetwork,SD:()=>N,E7:()=>A});var s=r(50467),n=r(40961),i=r(69487),a=r(37285),o=r(96379),l=r(71315),u=r(38102);let c=["SAML","SERVICE_UNAVAILABLE"],h={FORBIDDEN:["SAML error"],AUTHENTICATION:["Couldn\u2019t authenticate you"]},d={NOT_FOUND:[["repository","issue"]]};var p=r(51987);function f(e,t){let r=d[e];if(!r)return!1;for(let e of r){if(t.length!==e.length)continue;let r=!0;for(let s=0;s401&&404!==e.status){let s=await e.text(),n={url:e.url,timestamp:new Date().toISOString(),persistedQueryId:t,persistedQueryName:r,failureRequestId:e.headers.get("X-Github-Request-Id")},i=`HTTP error (${e.status}): ${s||"No additional text"}. Error Info: ${JSON.stringify(n)}`;if(429===e.status)throw{message:i,cause:e.status};throw Error(i,{cause:e.status})}}async function m(e,t,r,s="GET",n,i,a,o){return(await _(e,t,r,s,{isSubscription:!1,scope:void 0},n,i,a,o)).response}async function _(e,t,r,s="POST",n={},o,d,p,g){let w=JSON.stringify((0,i.stableCopy)({query:e,variables:r,...n.scopeObject?{scopeObject:n.scopeObject}:{}})),{isSubscription:m,scope:y,subscriptionTopic:v,dispatchTime:k}=n,E=function(e,t,r,s,n,i,a="/_graphql"){let o=[];if("GET"===e&&o.push(`body=${t}`),r&&o.push("subscription=1"),n&&o.push(`scope=${encodeURIComponent(n)}`),s&&o.push(`subscriptionTopic=${encodeURIComponent(s)}`),i&&o.push(`dispatchTime=${encodeURIComponent(i)}`),l.cg){let e=new URL(l.cg.location.href,l.cg.location.origin).searchParams.get("_features");e&&o.push(`_features=${e}`)}return o.length>0?`${a}?${o.join("&")}`:a}(s,encodeURIComponent(w),m,v,y,k,o),T=null;try{let{subscriptionId:r,requestId:n,json:i,status:o}=await S(E,s,e,t,w,d);if(T=r,p&&i.errors){let e=p[o];if(e)for(let r of i.errors){let s=e[r.type];s?.({persistedQueryName:t,errorMessage:r.message})}}let l=function(e,t,r,s){var n,i;if(n=t,i=e,"errors"in i&&(i.errors.filter(e=>{let t=c.includes(e.type)||!!h[e.type]?.includes(e.message),r=f(e.type,e.path);return t||r}).map(e=>{console.error(`Failed to fetch data. Please use this request ID when contacting support: ${n} Error: ${e.type}: ${e.message} (path: ${e.path})`)}),i.errors=i.errors.filter(e=>{let t=c.includes(e.type)||!!h[e.type]?.includes(e.message),r=f(e.type,e.path);return!t&&!r})),"errors"in e&&e.errors.length){let t=e.errors.map(e=>`GraphQL error: ${e.type}: ${e.message} (path: ${e.path})`).join(", "),n=new b(`${t} (Persisted query id: ${r})`,{cause:e.errors},e.extensions?.query_owning_catalog_service);if(s)(0,u.N7)(n),s.error(n);else throw n}if(!("data"in e)){let n=Error(`Expected data property in response: ${JSON.stringify(e)}. persistedQueryId: ${r}, requestId: ${t}`);if(s)(0,u.N7)(n),s.error(n);else throw n}return e}(i,n,e,g);return l&&(0,a.Av)(l),{subscriptionId:T,response:l}}catch(e){if(g)return"object"==typeof e&&null!==e&&"cause"in e&&429===e.cause||(0,u.N7)(e),g.error(e),{subscriptionId:T,response:{errors:[{message:"An error occurred while fetching data. Please try again later."}],extensions:{}}};throw e}}async function S(e,t,r,s,n,i){return y((0,a.RD)(e),t,r,s,n,i)}async function y(e,t,r,s,n,i){let a,l,c={...(0,p.kt)()};i?.issues_react_perf_test&&(c["X-LUC-Environment"]="issues");let h=(a="GET"===t?await fetch(e,{method:t,cache:"no-cache",credentials:"include",headers:{Accept:"application/json",...c}}):await (0,o.DI)(e,{method:t,headers:{Accept:"application/json",...c},...n?{body:n}:void 0})).headers.get("X-Subscription-ID"),d=a.headers.get("X-Github-Request-Id")||"",f=a.status;g.z.checkResponse(a),await w(a,r,s);try{l=await a.json()}catch(r){let t={error:r,status:f,url:e,requestId:d};throw(0,u.N7)(Error(`Failed to parse server JSON response ${JSON.stringify(t)}`)),Error(`Failed to parse server response. Please try again later. ${JSON.stringify(t)}`)}return{subscriptionId:h,requestId:d,json:l,status:f}}let v=[{kind:"linked",handle(e,t,r){if(null!=t&&t.getType()===i.ROOT_TYPE&&"node"===e.name&&r.hasOwnProperty("id"))return r.id}},{kind:"pluralLinked",handle(e,t,r){if(null!=t&&t.getType()===i.ROOT_TYPE&&"nodes"===e.name&&r.hasOwnProperty("ids"))return r.ids}}];var k=r(11418),E=r(73056),T=r(69982);function M(e){return(0,T.unstable_scheduleCallback)(T.unstable_LowPriority,e)}let P={cancel:()=>!1,schedule:e=>((0,n.unstable_batchedUpdates)(e),"")};let SSRNetwork=class SSRNetwork{execute(e,t,r){return this.relayNetwork.execute(e,t,r)}getPreloadedSubscriptions(){return this.preloadedSubscriptions}constructor(e,t={},r,n,a,o){(0,s._)(this,"relayNetwork",void 0),(0,s._)(this,"ssrPreloadedData",void 0),(0,s._)(this,"preloadedSubscriptions",void 0),(0,s._)(this,"warningsShown",void 0),(0,s._)(this,"enabled_features",void 0),(0,s._)(this,"maxAge",void 0),(0,s._)(this,"errorCallbacks",void 0),this.ssrPreloadedData=e,this.enabled_features=t,this.preloadedSubscriptions=r,this.warningsShown=new Set,this.maxAge=a,this.errorCallbacks=o,this.relayNetwork=i.Network.create((e,t)=>i.Observable.create(r=>{let s=function({params:e,variables:t,ssrPreloadedQueries:r,baseUrl:s,emitWarning:n,enabledFeatures:i,maxAge:a,errorCallbacks:o,observer:u}){if(!e.id)throw Error("params has no id property!");if(e.id&&r){let s=JSON.stringify(t),n=r.get(e.id)?.get(s),i=Math.floor(Date.now()/1e3),o=n?.timestamp;if(n&&(u.next(n),!(a&&o&&i>o+a)))return void u.complete();e.metadata?.isRelayRouteRequest&&(0,l.g5)()}let c="mutation"===e.operationKind?"POST":"GET";if(l.KJ)return m(e.id,e.name,t,c,s,i,o,u)}({params:e,variables:t,ssrPreloadedQueries:this.ssrPreloadedData,baseUrl:n,emitWarning:e=>{this.warningsShown.has(e)||(this.warningsShown.add(e),console.warn(e))},enabledFeatures:this.enabled_features,maxAge:a,errorCallbacks:this.errorCallbacks,observer:r});s instanceof Promise&&s.then(e=>{if(!Array.isArray(e)&&"extensions"in e&&e.extensions&&e.extensions.subscriptions){let t=e.extensions.subscriptions;for(let e in t)for(let r in this.preloadedSubscriptions.has(e)||this.preloadedSubscriptions.set(e,new Map),t[e])this.preloadedSubscriptions.get(e)?.set(r,t[e][r])}r.next(e),r.complete()})}),(e,t)=>(function(e,t,r=new Map){let s=e.id,n=e.name;return i.Observable.create(i=>{let a=()=>{},o=!1;return async function(){if(!s)throw Error("unexpected operation with no id!");let l=e.metadata?.scope,c=function(e,t,r,s){let n=s.get(e);if(n)e:for(let[e,s]of n){for(let[s,n]of Object.entries(JSON.parse(e)))if("$scope"===s&&r!==n||t[s]!==n)continue e;return s}}(s,t,l,r),h=null;if(c)h=c.subscriptionId,c.response&&i.next(c.response);else try{let e=await _(s,n,t,"GET",{isSubscription:!0,scope:l});h=e.subscriptionId,e.response&&i.next(e.response)}catch(e){if(e instanceof Error&&e.message.includes("Subscription halted"))return;throw e}try{let e=await (0,k.H)();if(o)return;let r=(0,E.$)(e,h,async({scope_object:e,subscription_topic:r,dispatch_time:a})=>{try{let{response:o}=await _(s,n,{...t},"GET",{isSubscription:!0,scopeObject:e,subscriptionTopic:r,dispatchTime:a,scope:l});o&&i.next(o)}catch(e){(0,u.N7)(e,{message:`Error in fetching update for ${s} with variables ${JSON.stringify(t)}`})}});r?.unsubscribe&&(a=r.unsubscribe)}catch(e){i.error(e)}}(),{get closed(){return o},unsubscribe(){o=!0,a()}}})})(e,t,this.preloadedSubscriptions))}};let A=(e,t)=>{let r=new SSRNetwork(new Map,{},new Map,e,void 0,t),s=new i.Environment({scheduler:P,store:new i.Store(new i.RecordSource,{gcReleaseBufferSize:50,queryCacheExpirationTime:3e5,gcScheduler:M}),getDataID:(e,t)=>{if("Viewer"===t)return null==e.id?(0,i.generateClientID)("client:root","viewer"):e.id;if("ProjectV2SingleSelectFieldOption"===t){let t=[];return e.id&&t.push(e.id),e.name&&t.push(e.name),e.color&&t.push(e.color),e.description&&t.push(function(e){let t=0;if(0===e.length)return t;for(let r=0;rr.getPreloadedSubscriptions()},s};function N({environment:e,query:t,variables:r={}}){let s=(0,i.getRequest)(t),n=(0,i.createOperationDescriptor)(s,r);return e.retain(n),(0,i.fetchQuery)(e,t,r,{fetchPolicy:"store-or-network"})}},33303:(e,t,r)=>{function s(){return Promise.resolve()}function n(){return new Promise(window.requestAnimationFrame)}async function i(e,t){let r,s=new Promise(t=>{r=self.setTimeout(t,e)});if(!t)return s;try{var n;await Promise.race([s,(n=t,new Promise((e,t)=>{let r=Error("aborted");r.name="AbortError",n.aborted?t(r):n.addEventListener("abort",()=>t(r))}))])}catch(e){throw self.clearTimeout(r),e}}function a(e){let t=[];return function(r){t.push(r),1===t.length&&queueMicrotask(()=>{let r=t.slice(0);t.length=0,e(r)})}}r.d(t,{G$:()=>n,k2:()=>s,rK:()=>a,uk:()=>i})},73056:(e,t,r)=>{r.d(t,{$:()=>a});var s=r(10204),n=r(33303);let i=new WeakMap;function a(e,t,r){let a;if(!e)throw Error("Not connected to alive");if(!t)throw Error("No channel name");let o=s.KK.parse(t);if(!o)throw Error("Invalid channel name");let l={subscriber:{dispatchEvent:e=>{e instanceof CustomEvent&&r(e.detail.data)}},topic:o},u=((a=i.get(e))||(a={subscribe:(0,n.rK)(t=>e.subscribe(t.flat())),unsubscribeAll:(0,n.rK)(t=>e.unsubscribeAll(...t))},i.set(e,a)),a);return u.subscribe([l]),{unsubscribe:()=>u.unsubscribeAll(l.subscriber)}}},86185:(e,t,r)=>{r.d(t,{z:()=>p});var s=r(35750),n=r(18150),i=r(87057),a=r(69599),o=r(82075);let l="VERSION_MISMATCH_LAST_TRIGGERED",u=(0,o.A)("localStorage",{ttl:9e7,throwQuotaErrorsOnSet:!1}),c=null;let VersionMismatchRateLimiter=class VersionMismatchRateLimiter{canTrigger(){let e=this.getLastTriggerTime();return null===e||Date.now()-e>=864e5}recordTrigger(){let e=Date.now();u.setItem(l,e.toString()),c=e}getLastTriggerTime(){let e=u.getItem(l);if(e){let t=parseInt(e,10);return isNaN(t)?null:t}return c}clearTriggerRecord(){u.removeItem(l),c=null}};let h=new VersionMismatchRateLimiter;var d=new WeakMap;let p=new class VersionMismatchDetector{registerApp(e,t){(0,s._)(this,d).set(e,t)}unregisterApp(e){(0,s._)(this,d).delete(e)}checkResponse(e,t){if("true"!==e.headers.get("X-GitHub-Version-Mismatch")||!(0,a.G7)("react_version_mismatch_detection")||!h.canTrigger())return!1;let r={clientVersion:(0,i.O)(),serverVersion:e.headers.get("X-GitHub-Server-Version")||void 0,requestUrl:e.url,responseHeaders:e.headers,appName:t};if(h.recordTrigger(),t){let e=(0,s._)(this,d).get(t);if(e)return e.onMismatchDetected(r),!0}else{let e=!1;for(let[t,n]of(0,s._)(this,d).entries()){let s={...r,appName:t};n.onMismatchDetected(s),e=!0}return e}return!1}constructor(){(0,n._)(this,d,{writable:!0,value:new Map})}}}}]); //# sourceMappingURL=packages_relay-environment_relay-environment_ts-680ea122b337.js.map